﻿package mortal.game.view.group.panel
{
    import Message.Public.*;
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.group.cellRenderer.*;
    import mortal.mvc.core.*;

    public class GroupInvitePanel extends GSprite
    {
        private var _inviteList:GTileList;
        private var _refreshBtn:GButton;
        private var _rejectAllBtn:GButton;

        public function GroupInvitePanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(13, 65, 778, 325, this, ImagesConst.PanelBg));
            this.pushUIToDisposeVec(UIFactory.bg(10, 66, 788, 22, this, ImagesConst.RegionTitleBg));
            var _loc_1:* = GlobalStyle.textFormatPutong;
            _loc_1.align = AlignMode.CENTER;
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30224), 0, 67, 160, 20, this, _loc_1));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30225), 158, 67, 100, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30219), 282, 67, 100, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30220), 377, 67, 100, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30217), 477, 67, 100, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30221), 577, 67, 100, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(30216), 695, 67, 100, 20, this));
            this._inviteList = UIFactory.tileList(22, 93, 750, 287, this);
            this._inviteList.rowHeight = 30;
            this._inviteList.columnWidth = 740;
            this._inviteList.horizontalGap = 1;
            this._inviteList.verticalGap = 1;
            this._inviteList.setStyle("skin", new Bitmap());
            this._inviteList.setStyle("cellRenderer", GroupInviteCellRenderer);
            this.addChild(this._inviteList);
            this._refreshBtn = UIFactory.gButton(Language.getString(30210), 315, 396, 65, 22, this);
            this._refreshBtn.configEventListener(MouseEvent.CLICK, this.refreshHandeler);
            this._rejectAllBtn = UIFactory.gButton(Language.getString(30227), 415, 396, 65, 22, this);
            this._rejectAllBtn.configEventListener(MouseEvent.CLICK, this.rejectAll);
            this.updateInviteList();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._inviteList.dispose(param1);
            this._refreshBtn.dispose(param1);
            this._rejectAllBtn.dispose(param1);
            this._inviteList = null;
            this._refreshBtn = null;
            this._rejectAllBtn = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function refreshHandeler(event:MouseEvent) : void
        {
            this.updateInviteList();
            return;
        }// end function

        private function rejectAll(event:MouseEvent) : void
        {
            var _loc_4:SGroupOper = null;
            var _loc_6:int = 0;
            var _loc_2:* = Cache.instance.group.inviteList;
            var _loc_3:* = _loc_2.length;
            var _loc_5:* = new Array();
            while (_loc_6 < _loc_3)
            {
                
                _loc_4 = new SGroupOper();
                _loc_4.fromEntityId = Cache.instance.role.entityInfo.entityId;
                _loc_4.toEntityId = (_loc_2[_loc_6] as SGroupOper).fromEntityId;
                _loc_4.fromPlayer = new SPublicPlayer();
                _loc_4.fromPlayer.guildId = new SEntityId();
                _loc_4.fromPlayer.copyId = new SEntityId();
                _loc_4.fromPlayer.entityId = Cache.instance.role.entityInfo.entityId;
                _loc_4.type = EGroupOperType._EGroupOperTypeReject;
                _loc_4.uid = (_loc_2[_loc_6] as SGroupOper).uid;
                _loc_5.push(_loc_4);
                _loc_6++;
            }
            if (_loc_5.length > 0)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GroupInviteReplyOper, _loc_5));
            }
            return;
        }// end function

        private function getDateProvider() : DataProvider
        {
            var _loc_3:SGroupOper = null;
            var _loc_4:Object = null;
            var _loc_1:* = new DataProvider();
            var _loc_2:* = Cache.instance.group.inviteList;
            for each (_loc_3 in _loc_2)
            {
                
                _loc_4 = {data:_loc_3};
                _loc_1.addItem(_loc_4);
            }
            return _loc_1;
        }// end function

        public function updateInviteList() : void
        {
            this._inviteList.dataProvider = this.getDateProvider();
            this._inviteList.drawNow();
            return;
        }// end function

    }
}
